package com.nwpu.am.controller.staff;

import com.nwpu.am.exception.BizException;
import com.nwpu.am.pojo.dto.OrderCreateDTO;
import com.nwpu.am.pojo.entity.Order;
import com.nwpu.am.pojo.entity.Part;
import com.nwpu.am.result.Result;
import com.nwpu.am.service.OrderService;
import com.nwpu.am.service.PartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * StaffController
 *
 * @author Roy
 * @version 1.0
 * {@code @date} 2024/6/5
 */

@RestController
@Validated
@RequestMapping("/staff")
@Slf4j
@Api(tags = "修理人员接口")
public class StaffController {
    @Resource
    OrderService orderService;
    @Resource
    PartService partService;

    @PostMapping("/createOrder")
    @ApiOperation("创建订单")
    public Result<String> createOrder(@RequestBody @Validated OrderCreateDTO order) throws BizException {


        try {
            orderService.createOrder(order);
        } catch (Exception e) {
            throw new BizException("订单创建失败");
        }

        return Result.success("订单创建成功");
    }

    @PostMapping("/displayOrderList")
    @ApiOperation("展示订单列表")
    public List<Order> displayOrderList() {
        return orderService.display();
    }

    @PostMapping("/displayPartList")
    @ApiOperation("展示零件列表")
    public List<Part> displayPartList() {
        return partService.display();
    }

}
